#include "main.h"
#include "cmsis_os.h"
#include "messager.h"

// ##
#define LOG_TAG     "notify"
#include "log.h"

// ##
osThreadId thread_notify_id = NULL;

#ifdef CFG_COMPONENTS_REVENT
/**
 * @description:
 * @param {char} *event
 * @param {void} *payload
 * @param {uint16_t} length
 * @return {*}
 */
void notify_rtc_handler(const char *event, void *payload, uint16_t length)
{
    log_info("Recv: event: %s, payload: %.*s\r\n", event, length, payload);
}
#endif

// ##
void thread_notify(const void *argument)
{
    // ##
    int32_t signal_recv = 0;

    osEvent event;

    log_info("%s starts to run\r\n", __func__);

    for (;;)
    {
        // ##
        event = osSignalWait(signal_recv, osWaitForever);

        if(event.status == osEventSignal)
        {
            // ##
            if(event.value.signals & SIGNAL_SYNC_BIT_RTC)
            {
                messager_notify(MSG_RTC_ALARM, 0);
            }
        }
        else
        {
            log_error("failed to osSignalWait.\r\n");
        }
    }
}
